// page/order/evaluate.js
Page({
  data: {
        isHide: 0,
        imgUrl: "/images/pro9.jpg",    //要评价的产品图片
        title: "戴安娜玫瑰11枝红色康乃馨 11支，红色石竹梅4枝",   //要评价的产品名称
        mark: ["非常差","差","一般","好","非常好"],
        flag1: 5,
        flag2: 5,
        flag3: 5,
        key1: "非常好",
        key2: "非常好",
        key3: "非常好",
        files: [] , 
        text: '', 
        gid: '',
        imgId:[]    
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (e) {
      var that = this;
      var app = getApp()
      // var uid = wx.getStorageSync('uid');
      console.log(e.id);
      wx.request({
        url: app.globalData.host + '&g=App&m=Order&a=evaluate', //仅为示例，并非真实的接口地址
        data: {id:e.id},
        header: {
          'content-type': 'application/json'
        },
        success: function (res) {
          that.setData({
            imgUrl: res.data.imgUrl,
            title: res.data.title,
            gid:e.id,
            isHide: 1
          });

        }
      })
  },
  changeStar1: function (e) {
      var that = this;
      that.setData({
          flag1: e.currentTarget.dataset.id,
          key1: e.currentTarget.dataset.key
      });
  },
  changeStar2: function (e) {
      var that = this;
      that.setData({
          flag2: e.currentTarget.dataset.id,
          key2: e.currentTarget.dataset.key
      });
  },
  changeStar3: function (e) {
      var that = this;
      that.setData({
          flag3: e.currentTarget.dataset.id,
          key3: e.currentTarget.dataset.key
      });
  },

  chooseImage: function (e) {
    var that = this;
    var app = getApp()
    wx.chooseImage({
      count:5,
      sizeType: ['compressed'],        // 可以指定是原图还是压缩图，默认二者都有
      sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机，默认二者都有
      success: function (res) {
      
        // 返回选定照片的本地文件路径列表，tempFilePath可以作为img标签的src属性显示图片
        for (var i = 0; i < res.tempFilePaths.length; i++) {
          wx.uploadFile({
            url: app.globalData.host + '&g=App&m=Order&a=oImg', //仅为示例，非真实的接口地址
            filePath: res.tempFilePaths[i],
            name: 'file',
            formData: {
              'tag': that.data.imgTag
            },
            success: function (res1) {
              that.setData({
                imgId: that.data.imgId + res1.data + ','
              })
              // console.log(that.data.imgId)
            }
          })
        }
        that.setData({
          files: that.data.files.concat(res.tempFilePaths),

        });
      }
    })
  },
  previewImage: function (e) {
      wx.previewImage({
          current: e.currentTarget.id, // 当前显示图片的http链接
          urls: this.data.files // 需要预览的图片http链接列表
      })
  } ,
  bindTextAreaBlur:function(e){
    this.setData({
      text: e.detail.value
    })
  },
  subform:function(e){
    var that = this;
    var app = getApp()
    var data = that.data
    if (data.text){
      wx.request({
        url: app.globalData.host + '&g=App&m=Order&a=upevaluate', //仅为示例，并非真实的接口地址
        data: { id: data.gid, evaluate: data.text, evaluate_img: data.imgId, evaluate_lv: data.flag1, evaluate1_lv: data.flag2, evaluate2_lv: data.flag3 },
        header: {
          'content-type': 'application/json'
        },
        success: function (res) {
          if (res.data.status){
              wx.setStorageSync('pjfh', 1) // 存储
              wx.navigateBack({
                  delta: 1
              })
            }
        }
      })
    }else{
      wx.showToast({
        title: '亲 还没输入评价呢！',
        duration: 2000
      })
    }
  }  
})